/**
 * 套件的模型定义
 */

import { getDefaultFields } from "../utils";



/**
 * 套件
 * @param app 
 */
export default (app) => {
  const DataTypes = app.Sequelize;


  const Model = app.model.define('template_def', {
    id: {
      type: DataTypes.INTEGER(8).UNSIGNED,
      allowNull: false,
      primaryKey: true,
      autoIncrement: true
    },
    title: {
      type: DataTypes.STRING(255),
      allowNull: false,
      comment: '标题'
    },

    desc: {
      type: DataTypes.STRING(512),
      allowNull: false,
      comment: '描述'
    },
    thumbnail: {
      type: DataTypes.STRING(512),
      allowNull: false,
      comment: '缩略图'
    },
    ...getDefaultFields()
  }, {
    tableName: 'template_def',
    timestamps: false
  });

  Model.sync({ alter: true });

  Model.associate = function () {
    app.model.TemplateDef.hasMany(app.model.PageDef, {
      foreignKey: 'template_id',
      constraints: false,
      sourceKey: 'id'
    });
  }


  return Model;
}
